#ifndef CWINDOWBAR_H
#define CWINDOWBAR_H

#include <QDebug>
#include <QHBoxLayout>
#include <QLabel>
#include <QMenuBar>
#include <QPushButton>
#include <QWidget>

#include "CBaseTitleBar.h"
#include "CToolButton.h"

class CWindowBarTitleLabel;

class CWindowBar : public CBaseTitleBar {
    Q_OBJECT
public:
    explicit CWindowBar(QWidget *parent = nullptr);
    ~CWindowBar();

    void reloadStrings();

private:
    void init();

public:
    QMenuBar *menuBar() const;
    void setMenuBar(QMenuBar *menuBar);

    bool isMouseFree() const override;

    void reloadMaxButtonState();

private:
    CToolButton *m_minButton;
    CToolButton *m_maxButton;
    CToolButton *m_closeButton;
    CToolButton *m_iconButton;

    QSpacerItem *m_spacerLeft, *m_spacerRight;
    CWindowBarTitleLabel *m_titleLabel;

    QMenuBar *m_menuBar;
    QHBoxLayout *m_layout;

    void handleMinimize();
    void handleMaximize();
    void handleClose();
    void handleWindowTitleChanged(const QString &title);

    void updateMaxButtonToolTip();
    void drawCentralTitle(QPainter &painter);

protected:
    void updateBarVisible() override;
    void paintEvent(QPaintEvent *event) override;

signals:
    void minRequested();
    void maxRequested();
    void closeRequested();
};

#endif // CWINDOWBAR_H
